package visualization;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JFrame;

public class Colormap {

	public static float RED_BASE = 0/360f;
	public static float GREEN_BASE = 120/360f;
	public static float BLUE_BASE = 240/360f;

	public static Colormap RED = new Colormap(RED_BASE);
	public static Colormap GREEN = new Colormap(GREEN_BASE);
	public static Colormap BLUE = new Colormap(BLUE_BASE);
	
	public static Colormap FIXED = new Colormap(0) {
		@Override
		public Color getColor(int index) {
			switch(index) {
			case 0: return Color.blue.darker();
			case 1: return Color.green;
			case 2: return Color.cyan.darker();
			case 3: return Color.orange;
			case 4: return Color.gray;
			default: return Color.black;
			}
		}
	};
	
	float base;
	
	public Colormap(float base) {
		this.base = base;
	}
	
	public Color getColor(int index) {
		float hue = base, b = 1f;
		if (index == 0) {}
		else if (index == 1) { hue += 60/360f; }
		else if (index == 2) { hue += 30/360f; }
		else if (index == 3) { hue += 90/360f; }
		else if (index == 4) { hue += 20/360f; b = 0.8f; }
		else if (index == 5) { hue += 40/360f; b = 0.8f;}
		else if (index == 6) { hue += 80/360f; b = 0.8f;}
		else if (index == 7) { hue += 100/360f; b = 0.8f;}
		else {
			hue = base+((base*360 + (index-8)*10)%120)/360f; b = 0.6f;
		}
		
		return Color.getHSBColor(hue, 0.9f, b);
	}
	
	public static void main(String[] args) {
		JFrame f = new JFrame("test") {
			@Override
			public void paint(Graphics g) {
				g.clearRect(0,0,500,500);
				Colormap map = new Colormap(Colormap.RED_BASE);
				for (int i = 0; i < 16; i++) {
					g.setColor(map.getColor(i));
					g.fillRect(50+i*50,50, 50, 50);
				}
				map = new Colormap(Colormap.GREEN_BASE);
				for (int i = 0; i < 16; i++) {
					g.setColor(map.getColor(i));
					g.fillRect(50+i*50,150, 50, 50);
				}
				map = new Colormap(Colormap.BLUE_BASE);
				for (int i = 0; i < 16; i++) {
					g.setColor(map.getColor(i));
					g.fillRect(50+i*50,250, 50, 50);
				}
			}
		};
		f.setSize(500, 500);
		f.setVisible(true);
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
}
